<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #ul {

            list-style: none;
        }

        li {
            border-radius: 50%;
            position: absolute;
        }
    </style>
</head>

<body>

    <div>
        <h1>成绩</h1>
        <h2 id="h1"></h2>
    </div>
    <div id="box">

        <h3>时间</h3>
        <h4 id="h3"></h4>
    </div>




    <ul id="ul"></ul>



    <script src="../random_number.js"></script>
    <script>
        class Ball {
            constructor(number, r, g, b) {
                this.number = number;
            }
            render(number, r, g, b) {
                let li = document.createElement('li');
                let x = random(innerWidth - this.number * 2);
                let y = random(innerHeight - this.number * 2);
                if (y < 0) {
                    y = this.number * 2
                }
                if (x < 0) {
                    x = this.number * 2
                }
                if (y > innerHeight - this.number * 2) {
                    y = innerHeight - this.number * 2
                }
                if (x > innerWidth - this.number * 2) {
                    x = innerWidth - this.number * 2
                }
                let inner = 0.9
                let i = 0;
                let timer = setInterval(function () {
                    // console.log(111);
                    i += 2;
                    if (i < number) {
                        li.style.cssText = `
                        width:${i}px;
                        height:${i}px;
                        background-color: rgba(${r},${g},${b},${inner-=0.009});
                        box-shadow: 3px 3px  10px rgba(${r},${g},${b},${inner-=0.009});
                        left:${x-i/2}px;
                        top:${y-i/2}px;
                        background-color:${this.bkColor};`
                    } else {
                        clearInterval(timer);
                        ul.innerHTML = ''

                    }
                }, 100)
                li.onclick = function () {
                    clearInterval(timer);
                    ul.removeChild(li);
                }
                ul.appendChild(li);
            }
        }

        let timer_2 = setInterval(() => {
            let number = random(50, 200);
            let r = random(255);
            let g = random(255);
            let b = random(255);
            let obj = new Ball(number);
            obj.render(number, r, g, b);
        }, 1000)


        let i = 0;
        let z = 20;
        setInterval(() => {
            if (z >= 0) {
                h3.innerText = `${z--}s`
                console.log(z);
            } else {
                clearInterval(timer_2);
                ul.innerHTML = '';
                box.innerHTML = ''
            }
        }, 1000)
        document.body.onmousedown = function () {
            console.log('点中了');
            i += 1;
            h1.innerText = `${i}`
        }
    </script>
</body>

</html>